﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using NHibernate.Cfg;
using NHibernate.Dialect;

namespace HYCodeBase.SqlUtility.ORMSuit
{
	public abstract class ConfigurationPacker
	{
		protected ConfigurationPacker()
		{
			this.m_dicUseProperties.Add("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
			this.m_dicUseProperties.Add("show_sql", true.ToString());
			this.m_dicUseProperties.Add("cache.provider_class", "NHibernate.Cache.HashtableCacheProvider");
			this.m_dicUseProperties.Add("cache.use_query_cache", true.ToString());
			this.m_dicUseProperties.Add("cache.use_second_level_cache", true.ToString());
			Type typeFromHandle = typeof(UseCacheFactory);
			this.m_dicUseProperties.Add("cache.query_cache_factory", typeFromHandle.FullName + "," + typeFromHandle.Assembly.FullName);
		}

		protected ConfigurationPacker(string rootName, string passWord)
		{
			this.m_useRootName = rootName;
			this.m_usePassWord = passWord;
		}

		protected abstract string MakeConnectionString();

		internal abstract Dialect GetUseDialect();

		internal bool CheckDriverFileExist()
		{
			return string.IsNullOrWhiteSpace(this.m_strUseDirverFileName) && File.Exists(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName + "\\" + this.m_strUseDirverFileName);
		}

		internal void AddToNHibernateConfiguration(Configuration inputNHibernateCfg)
		{
			if (!this.m_dicUseProperties.ContainsKey("connection.connection_string"))
			{
				string value = this.MakeConnectionString();
				this.m_dicUseProperties.Add("connection.connection_string", value);
			}
			foreach (KeyValuePair<string, string> item in this.m_dicUseProperties)
			{
				inputNHibernateCfg.Properties.Add(item);
			}
		}

		protected const string m_strDialect = "dialect";

		protected const string m_strProvider = "connection.provider";

		protected const string m_strDriverclass = "connection.driver_class";

		protected const string m_strConnectionstring = "connection.connection_string";

		protected const string m_strDefualtProvider = "NHibernate.Connection.DriverConnectionProvider";

		protected const string m_strShowSqlInConsole = "show_sql";

		protected const string m_strSchemaAuto = "hbm2ddl.auto";

		protected const string m_strUpdate = "update";

		protected const string m_strCache = "cache.provider_class";

		protected const string m_strDefualtChacheProvider = "NHibernate.Cache.HashtableCacheProvider";

		protected const string m_strUseChache = "cache.use_second_level_cache";

		protected const string m_strUseChacheForQuery = "cache.use_query_cache";

		protected const string m_strUseCacheFactory = "cache.query_cache_factory";

		protected const string m_strComma = ",";

		protected string m_useRootName;

		protected string m_usePassWord;

		protected string m_strUseDirverFileName;

		protected Dictionary<string, string> m_dicUseProperties = new Dictionary<string, string>();
	}
}
